<template>
    <AppView :title="title" :menu-list="testMenuListData" >
        <div slot="content">
            <router-view/>
        </div>
    </AppView>
</template>

<script>
    import AppView from "../../components/basic/AppView";
    import caishen from "../../assets/image/caishen.png";

    export default {
        name: 'Home',
        components: {
            AppView,
        },
        data: function () {
            return {
                title:'权限管理',
                testMenuListData: {
                    baseRoute: "admin",
                    menuList: [
                        {
                            title: "权限管理",
                            icon: caishen,
                            items: [
                                {
                                    route: "",
                                    text: "角色管理",
                                    default: true
                                },
                                {
                                    route: "a2",
                                    text: "管理员管理"
                                },
                            ]
                        },
                        {
                            title: "系统配置",
                            icon: caishen,
                            items: [
                                {
                                    route: "a3",
                                    text: "参数配置"
                                }
                            ]
                        }
                    ],
                }
            }
        },
        beforeMount() {
          let userRole = JSON.parse(localStorage.getItem('user')).userRoles
           this.testMenuListData.menuList = this.testMenuListData.menuList.filter(item => {
            item.items = item.items.filter(itm => {
              let i =''
              if (itm.route){
               i = `/${this.testMenuListData.baseRoute}/${itm.route}`
              }else {
                i=`/${this.testMenuListData.baseRoute}`
              }
              if (userRole.indexOf(i)>-1) return itm
            })
            if (item.items.length > 0) return item
          })
        }
    }
</script>
